// 导入定义验证规则的包
const joi = require('joi')

// 定义用户名和密码的验证规则
const username = joi.string().alphanum().min(1).max(10).required()

const password = joi.string().pattern(/^[\S]{6,15}$/).required()

const id = joi.number().integer().min(1).required()

const nickname = joi.string().required()

const email = joi.string().email().required()

const avatar = joi.string().dataUri().required()

// 定义验证注册和登录表单数据的规则对象
exports.reg_login_schema = {
    body: {
        username,
        password,
    }
}
exports.reg_reguser_schema = {
    body: {
        username,
        password,
        nickname,
        email
    }
}
// 定义验证修改用户信息表单数据的规则对象
exports.update_userinfo_schema = {
    body: {
        id,
    }
}

//  定义验证修改密码表单数据的规则对象

exports.update_password_schema = {
    body:{
        oldPwd:password,
        newPwd:joi.not(joi.ref('oldPwd')).concat(password)
    }
}

// 定义验证修改头像表单数据的规则对象

exports.update_avatar_schema = {
    body:{
        avatar
    }
}